package com.youhp.spire.xls.demo.Data;

import com.spire.xls.*;

public class SetDataValidationOnSeparateSheet {
    public static void main(String[] args) {

        Workbook workbook = new Workbook();
        workbook.loadFromFile("data/SetDataValidationOnSeparateSheet.xlsx");

        //This is the first sheet
        Worksheet sheet1 = workbook.getWorksheets().get(0);

        sheet1.getCellRange("B10").setText("Here is a dataValidation example.");

        //This is the second sheet
        Worksheet sheet2 = workbook.getWorksheets().get(1);

        //Enable the data can be from different sheet.
        sheet2.getParentWorkbook().setAllow3DRangesInDataValidation(true);
        sheet1.getCellRange("B11").getDataValidation().setDataRange(sheet2.getCellRange("A1:A7"));

        workbook.saveToFile("output/SetDataValidationOnSeparateSheet.xlsx", ExcelVersion.Version2013);
    }
}
